<?php 
include ('m_user.php');
if (isset($_POST) && isset($_POST['login']))
{
	$user=mysql_escape_string($_POST['name']);
	$pass=md5(mysql_escape_string($_POST['pass']));
	$rl=checkUser($user,$pass);
	
	session_start();
	if(mysql_num_rows($rl)!= 0)
		{
			$row=mysql_fetch_row($rl);
		 	$_SESSION['logged']=true;
			$_SESSION['user']=$row;	
			//echo $_SESSION['user'][1];
			if($_SESSION['user'][4]=='user')
			{
				header('location:/cfshop/home.php');
				//header('location:/cfshop/User/a_user.php');
			}
			else header('location:/cfshop/User/a_user.php');
		
		}
	else 
		{
			$_SESSION['user']= "null";
		 	$_SESSION['logged']=false;
			//echo $_SESSION['user'];
			header('location:v_login.php');
		}
}
if (isset($_POST) && isset($_POST['edit']))
	{
	 	$id=$_POST['userid'];
		$name=$_POST['txtName'];
		$pass=$_POST['txtPass'];
		$email=$_POST['txtEmail'];
		$role=$_POST['Role'];
		
		$rl=updateUser($id, $name, $pass, $email, $role);
		header('location:/cfshop/User/a_user.php');
	}
	
if (isset($_POST) && isset($_POST['delete']))
{
 	$id=$_POST['id'];
	$rl=deleteUser($id);
	if ($rl==1)
	{
	header('location:/cfshop/User/a_user.php');
	}
}
if (isset($_POST) && isset($_POST['change_pass']))
	{
		$id=$_POST['idchange'];
	 	$pass=md5(mysql_escape_string($_POST['passnew']));
		$rl=changepass($id, $pass);
		if ($rl==1)
		{
		header('location:/cfshop/User/a_user.php');
		}
		header('location:/cfshop/home.php');
	}
	
?>